package service

import (
	"apitestAfterGo/dao"
	"apitestAfterGo/domain"
	"apitestAfterGo/dto"
	"github.com/zhuxiujia/GoMybatis"
)

type systemInfoService struct {
	systemInfoMapper     *domain.SyetemInfoMapper
	DeleteSystemInfoById func(id int) (int64, error)                                  `tx:"" rollback:"error"`
	GetAllSystemCount    func(dto dto.SystemInfoPageDto) (int, error)                 `tx:"" rollback:"error"`
	GetSystemInfosByPage func(dto dto.SystemInfoPageDto) ([]domain.SystemInfo, error) `tx:"" rollback:"error"`
	GetSystemInfoById    func(id int) (domain.SystemInfo, error)                      `tx:"" rollback:"error"`
	AddSystemInfo        func(info domain.SystemInfo) (int, error)                    `tx:"" rollback:"error"`
	ModifySystemInfoById func(info domain.SystemInfo) (int, error)                    `tx:"" rollback:"error"`
	GetSystemsBySystemId func(id int) ([]domain.SystemInfo, error)                    `tx:"" rollback:"error"`
}

var SystemInfoServiceImpl systemInfoService

func init() {
	SystemInfoServiceImpl = systemInfoService{
		systemInfoMapper: &dao.SystemInfoMapper,
		DeleteSystemInfoById: func(id int) (int64, error) {
			return SystemInfoServiceImpl.systemInfoMapper.DeleteTemplate(id)
		},
		GetAllSystemCount: func(dto dto.SystemInfoPageDto) (int, error) {
			return SystemInfoServiceImpl.systemInfoMapper.GetAllSystemCount(dto)
		},
		GetSystemInfosByPage: func(dto dto.SystemInfoPageDto) ([]domain.SystemInfo, error) {
			dto.Current = (dto.Current - 1) * dto.PageSize
			return SystemInfoServiceImpl.systemInfoMapper.GetSystemInfosByPage(dto)
		},
		GetSystemInfoById: func(id int) (domain.SystemInfo, error) {
			return SystemInfoServiceImpl.systemInfoMapper.GetSystemInfoById(id)
		},
		AddSystemInfo: func(info domain.SystemInfo) (int, error) {
			return SystemInfoServiceImpl.systemInfoMapper.AddSystemInfo(info)
		},
		ModifySystemInfoById: func(info domain.SystemInfo) (int, error) {
			return SystemInfoServiceImpl.systemInfoMapper.ModifySystemInfoById(info)
		},
		GetSystemsBySystemId: func(id int) ([]domain.SystemInfo, error) {
			return SystemInfoServiceImpl.systemInfoMapper.GetSystemsBySystemId(id)
		},
	}
	GoMybatis.AopProxyService(&SystemInfoServiceImpl, &dao.Engine)
}
